﻿using System;
using System.Collections.Generic;
using ICSharpCode.Decompiler.ILAst;
using Mono.Cecil;

namespace CSLua
{
	// Token: 0x02000017 RID: 23
	public class LuaCodeWriter : CodeWriter
	{
		// Token: 0x060000C3 RID: 195 RVA: 0x000050CC File Offset: 0x000032CC
		public override CodeWriter luaNil()
		{
			base.code(" nil ");
			return this;
		}

		// Token: 0x060000C4 RID: 196 RVA: 0x000050DB File Offset: 0x000032DB
		public LuaCodeWriter(TypeDefinition type) : base(type)
		{
		}

		// Token: 0x1700002E RID: 46
		// (get) Token: 0x060000C5 RID: 197 RVA: 0x000050EF File Offset: 0x000032EF
		public override ITokens tokens
		{
			get
			{
				return this._tokens;
			}
		}

		// Token: 0x060000C6 RID: 198 RVA: 0x000050F8 File Offset: 0x000032F8
		public override CodeWriter beginDefineMethod(string typeName, bool isStatic, string methodName, Action param)
		{
			base.codeFormat("function {0}{1}{2}(", new object[]
			{
				typeName,
				isStatic ? "." : ":",
				methodName
			});
			if (param != null)
			{
				param();
			}
			return base.code(")");
		}

		// Token: 0x060000C7 RID: 199 RVA: 0x00005147 File Offset: 0x00003347
		public override CodeWriter endDefineMethod()
		{
			return base.code("end");
		}

		// Token: 0x060000C8 RID: 200 RVA: 0x00005154 File Offset: 0x00003354
		protected override void writeLocalValueDefine(string valueName, string initValue)
		{
			if (initValue == null)
			{
				base.codeFormat("local {0}", new object[]
				{
					valueName
				});
				return;
			}
			base.codeFormat("local {0} = {1}", new object[]
			{
				valueName,
				initValue
			});
		}

		// Token: 0x060000C9 RID: 201 RVA: 0x0000518A File Offset: 0x0000338A
		public override CodeWriter beginLambda()
		{
			base.code("function()");
			return this;
		}

		// Token: 0x060000CA RID: 202 RVA: 0x00005199 File Offset: 0x00003399
		public override CodeWriter endLambda()
		{
			base.code("end");
			return this;
		}

		// Token: 0x060000CB RID: 203 RVA: 0x000051A8 File Offset: 0x000033A8
		public override void reportExpressionError(MethodBodyPhase methodBuilder, ILNode expressionContext, ILNode expression, string msg)
		{
			string expString = expression.ToString();
			base.code("###([=[" + expString + "]=])");
			int line = methodBuilder.getExpressionStartLine(expression);
			if (line == -1)
			{
				line = methodBuilder.getExpressionStartLine(expressionContext);
			}
			string file = methodBuilder.getSrcFile();
			if (file == null)
			{
				file = "unknow";
			}
			this.errorBuilder.AppendFormat(string.Concat(new object[]
			{
				"错误:",
				msg,
				"，在文件 {0} {1}行 \n 函数：",
				methodBuilder.Method,
				"\n ILAst:{2}\n"
			}), file, line, expString);
		}

		// Token: 0x060000CC RID: 204 RVA: 0x0000523C File Offset: 0x0000343C
		public override CodeWriter callVirtualFunc<T>(string self, string func, IEnumerable<T> ie, CodeWriter.DotItem<T> item)
		{
			base.code(self).code(":").code(func).code("(");
			base.dot<T>(ie, item);
			base.code(")");
			return this;
		}

		// Token: 0x060000CD RID: 205 RVA: 0x00005277 File Offset: 0x00003477
		public override CodeWriter commentLine(string common)
		{
			return base.code("--" + common.Replace('\n', ' ')).nextLine();
		}

		// Token: 0x060000CE RID: 206 RVA: 0x00005298 File Offset: 0x00003498
		public override CodeWriter comment(string common)
		{
			return base.code("--[===[" + common + "]===]").nextLine();
		}

		// Token: 0x060000CF RID: 207 RVA: 0x00005058 File Offset: 0x00003258
		public override void reportExpressionNotsupport(MethodBodyPhase methodBuilder, ILNode expressionContext, ILNode expression)
		{
			this.reportExpressionError(methodBuilder, expressionContext, expression, "不支持的表达式");
		}

		// Token: 0x0400003E RID: 62
		private LuaToken _tokens = new LuaToken();
	}
}
